#pragma once

#include "Material.h"
#include "IniFile.h"
#include "DAEFloat3.h"
#include <map>
#include <vector>
#include <iostream>
#include <fstream>
#include "util.h"

/**
* Reads a lightwave material file.
* @author Koen Samyn
*/
class MaterialReader
{
public:
	/**
	* Creates a new material reader object.
	* @param gameConfig the game configuration file.
	* @param fileName the filename for the 
	*/
	MaterialReader(IniFile* gameConfig,tstring fileName);
	/**
	* Destroys the MaterialReader object.
	*/
	virtual ~MaterialReader(void);
	/**
	* Read the material.
	*/
	void Read();
	/**
	* Read the start of a material definition.
	* @param line the current line in the material file.
	*/
	void ReadMaterialName(tstring& line);
	/**
	* Read the ambient color for the material definition.
	* @param line the current line in the material file.
	*/
	void ReadAmbientColor(tstring& line);
	/**
	* Read the diffuse color for the material definition.
	* @param line the current line in the material file.
	*/
	void ReadDiffuseColor(tstring& line);
	/**
	* Read the specular color for the material definition.
	* @param line the current line in the material file.
	*/
	void ReadSpecularColor(tstring& line);
	/**
	* Read the transparancy for the material definition.
	* @param line the current line in the material file.
	*/
	void ReadTransparancy(tstring& line);
	/**
	* Read the shininess for the material definition.
	* @param line the current line in the material file.
	*/
	void ReadShininess(tstring& line);
	/**
	* Read the diffuse texture for the material.
	* @param line the current line in the material file.
	*/
	void ReadDiffuseTexture(tstring& line);
	/**
	* Read the specular texture for the material.
	* @param line the current line in the material file.
	*/	
	void ReadSpecularTexture(tstring& line);
	/**
	* Read the normal map texture for the material.
	* @param line the current line in the material file.
	*/
	void ReadNormalMapTexture(tstring& line);
	/**
	* Read the shader for this material.
	* @param line the current line in the material file.
	*/
	void ReadShader(tstring& line);
	/**
	* Gets the material with the provided name.
	* @param materialName the name for the material.
	* @return a material pointer.
	*/ 
	Material* GetMaterial(tstring& name);
	/**
	* Checks if the material with the given name exists.
	* @param materialName the name for the material.
	* @return true if the material exists , false otherwise.
	*/
	bool HasMaterial(tstring& name);
private:
	/**
	* The game configuration file
	*/
	IniFile* m_GameConfig;
	/**
	* The file with the material definitions.
	*/
	tstring m_FileName;
	/**
	* The parentdirectory of this file.
	*/
	tstring m_ParentDir;
	/**
	* The current material.
	*/
	Material* m_CurrentMaterial;
	
	/**
	* a map with that links object names in the .obj file to material definitions.
	*/
	map<tstring,Material*> m_Materials;
	/**
	* The input stream.
	*/
	tifstream m_Input;
	/**
	* helps with parsing the file.
	*/
	vector<tstring> m_ParseHelp;

	/**
	* Reads a color from the current m_ParseHelp.
	* @param line the line to parse.
	* @return a D3DXVECTOR3 value with the parsed color.
	*/
	DAEFloat3 ReadColor(tstring& line);
	/**
	* Reads a float from the current m_ParseHelp.
	* @param line the line to parse.
	* @return the float value.
	*/
	float ReadFloat(tstring& line);
	/**
	* Reads a string from the current m_ParseHelp.
	* @param line the line to parse.
	* @return the tstring value.
	*/ 
	tstring ReadString(tstring& line);
	// -------------------------
	// Disabling default copy constructor and default assignment operator.
	// If you get a linker error from one of these functions, your class is internally trying to use them. This is
	// an error in your class, these declarations are deliberately made without implementation because they should never be used.
	// -------------------------

	MaterialReader(const MaterialReader& t);
	MaterialReader& operator=(const MaterialReader& t);
};
